package util.core;

import util.input.Parser;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        long time = System.nanoTime();
        Periodic.initialize();
        long end = System.nanoTime();
        System.out.println("Memory loadtime: " + (end - time) / 1000000.0 + " milliseconds");
        test();

    }

    public static void test() {
        for (int i = 0; i < 20; i++) {
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                doOther();
                doStuff(br);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static void doOther() {
        try {
            for (Atom c : Periodic.elements.values())
                System.out.println(c.info());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void doStuff(BufferedReader br) throws Exception {

        String s = br.readLine();
        while (!s.equals("end")) {
            Equation equation = Parser.read(s);
            if (equation != null) {
                long time = System.nanoTime();
                equation.balance();
                long end = System.nanoTime();

                System.out.println("Calc time: " + (end - time) / 1000000.0 + " milliseconds");
                System.out.println(equation);
                System.out.println(Format.toFormattedString(equation) + "\n");
            }

            s = br.readLine();
        }

    }


}

